package 力扣日常刷题.木22一月.第16天0128;

/**
 * @author 帅小伙
 * @date 2022/1/28
 * @description
 */
public class Demo23字符串简单上升下降字符串 {

    public String sortString(String s) {
        int[] num = new int[26];
        for (int i = 0; i < s.length(); i++) {
            num[s.charAt(i) - 'a']++;
        }

        StringBuffer sb = new StringBuffer();
        while (sb.length() < s.length()) {
            for (int i = 0; i < 26; i++) {
                if(num[i] > 0){
                    sb.append((char)(i+'a'));
                    num[i]--;
                }
            }
            for (int i = 25; i >=0; i--) {
                if(num[i] > 0){
                    sb.append((char)(i+'a'));
                    num[i]--;
                }
            }
        }
        return sb.toString();
    }
}
